<template>
	<view class="data">
		<view class="top">
			<view class="top_title">
				<view class="">数据中心</view>
				<view class="top_right" v-if="!isAgency">
					<image src="../../static/img/ic_head.png" @click="navlower()"></image>
				</view>
			</view>
		</view>
		<view class="content">
			<view class="content_sw">
				<u-tabs :list="tab.list" :is-scroll="false" :current="tab.current" @change="tabchange" font-size="28" active-color="#007AFF"></u-tabs>
			</view>
			<dataModule0 v-show="tab.current == 0" @refreshData="refreshData" :res="dataCenterData.Zl"></dataModule0>
			<dataModule1 v-show="tab.current == 1" @refreshData="refreshData" :res="dataCenterData.Md"></dataModule1>
			<dataModule2 v-show="tab.current == 2" @refreshData="refreshData" :res="dataCenterData.Yh"></dataModule2>
			<dataModule3 v-show="tab.current == 3" @refreshData="refreshData" :res="dataCenterData.Zf"></dataModule3>
			<dataModule4 v-show="tab.current == 4" @refreshData="refreshData" :res="dataCenterData.Wm" :cityData="cityData"></dataModule4>
		</view>
	</view>
</template>

<script>
	import { datacenter } from '../../api/index.js'
	import dataModule0 from '@/components/data/datamodule0.vue'
	import dataModule1 from '@/components/data/datamodule1.vue'
	import dataModule2 from '@/components/data/datamodule2.vue'
	import dataModule3 from '@/components/data/datamodule3.vue'
	import dataModule4 from '@/components/data/datamodule4.vue'
	export default {
		onLoad() {
			this.init()
		},
		data() {
			return {
				aid:'',
				cityData:[],//城市数据(暂时不用)
				tab:{
					list: [{
						name: '总览'
					},
					{
						name: '门店'
					}, 
					{
						name: '用户'
					}, 
					{
						name: '支付'
					}, 
					{
						name: '外卖'
					}],
					current: 0
				},
				dataCenterData:{ //数据中心所有数据
					Zl:{
						newshop: {
							"basic_shop": {
								"total_num": 0,
								"new_num": 0,
								"flag": 0,
								"d2d": 0
							},
							"waimai_shop": {
								"total_num": 0,
								"new_num": 0,
								"flag": 0,
								"d2d": 0
							}
						},
						newusers: {
							"total_num": 0,
							"new": {
								"num": 0,
								"flag": 0,
								"d2d": 0
							},
							"conversion": {
								"num": 0,
								"flag": 0,
								"d2d": 0
							}
						},
						waimaiorders: {
							payment: {
								total_payment: 0,
								self_payment: 0,
								shop_payment: 0,
								platform_payment: 0,
								flag: 0,
								d2d: 0
							},
							num: {
								total_num: 0,
								self_num: 0,
								shop_num: 0,
								platform_num: 0,
								flag: 0,
								d2d: 0
							}
						},
						payorders: {
							payment: {
								total_payment: 0,
								tangshi_money: 0,
								scan_qr_buy_money: 0,
								taika_money: 0,
								flag: 0,
								d2d: 0
							},
							num: {
								total_num: 0,
								tangshi_num: 0,
								scan_qr_buy_num: 0,
								taika_num: 0,
								flag: 0,
								d2d: 6
							}
						}
					},
					Yh:{
						"total_num": 0,
						"new": {
						  "num": 0,
						  "flag": 0,
						  "d2d": 0
						},
						"conversion": {
						  "num": 0,
						  "flag": 0,
						  "d2d": 0
						}
					},//用户模块数据
					Md:{
						"basic_shop": {
							"total_num": 0,
							"new_num": 0,
							"flag": 0,
							"d2d": 0
						},
						"waimai_shop": {
							"total_num": 0,
							"new_num": 0,
							"flag": 0,
							"d2d": 0
						}
					},//门店模块数据
					Zf:{
						"payment": {
							"total_payment": 0,
							"tangshi_money": 0,
							"scan_qr_buy_money": 0,
							"taika_money": 0,
							"flag": 0,
							"d2d": 0
						},
						"num": {
							"total_num": 0,
							"tangshi_num": 0,
							"scan_qr_buy_num": 0,
							"taika_num": 0,
							"flag": 0,
							"d2d": 0
						}
					},//支付模块数据
					Wm:{
						"payment": {
							"total_payment": 0,
							"self_payment": 0,
							"shop_payment": 0,
							"platform_payment": 0,
							"flag": 0,
							"d2d": 0
						},
						"num": {
							"total_num": 0,
							"self_num": 0,
							"shop_num": 0,
							"platform_num": 0,
							"flag": 0,
							"d2d": 0
						}
				  }, //外卖模块数据
				},
				dataCenterObj:{ //数据中心接口入参
					Zl:{
						data_type:1,
						check_type:1, //全部/我的数据
					}, //总览模块入参
					Md:{
						data_type:4,
						check_type:1, //全部/我的数据
						seachtime:2  //时间
					}, //门店模块入参
					Yh:{
						data_type:5,
						check_type:1, //全部/我的数据
						seachtime:2  //时间
					},//用户模块入参
					Zf:{
						data_type:2,
						check_type:1, //全部/我的数据
						seachtime:2  //时间
					},//用户模块入参
					Wm:{
						data_type:3,
						check_type:1, //全部/我的数据
						seachtime:2  //时间
					} //外卖模块入参
				},
				isAgency:true  //是否显示我的下级ture=隐藏，false=显示
			}
		},
		methods: {
			init:function(){
				this.aid = this.$storage('global').getItemSync('loginInfo').aid;
				this.getDatacenter()
				this.isAgency = this.user.is_agency
			},
			tabchange:function(index){
				this.tab.current = index;
				this.getDatacenter()
			},
			getDatacenter:function(){
				let index = this.tab.current;
				const dataTypeobj = {
					'0':'Zl',//总览数据
					'1':'Md',//外卖订单
					'2':'Yh',//用户数据
					'3':'Zf',//支付数据
					'4':'Wm',//外卖订单
				}
				
				let dataObj = this.dataCenterObj[dataTypeobj[index]];
				dataObj.aid = this.aid;
				console.log(dataObj)
				datacenter(dataObj).then((res)=>{
					console.log(res)
					if(index == 0){
						this.dataCenterData.Zl = res.data;
					}else if(index == 1){
						this.dataCenterData.Md = res.data;
					}else if(index == 2){
						this.dataCenterData.Yh = res.data;
					}else if(index == 3){
						this.dataCenterData.Zf = res.data;
					}else if(index == 4){
						this.dataCenterData.Wm = res.data;
					}
				})
			},
			refreshData:function(data){
				console.log(data)
				this.dataCenterObj[data.type] = data.data;
				this.getDatacenter();
			},
			navlower:function(){
				uni.navigateTo({
					url: '../dataLower/dataLower'
				});
			}
		},
		components: {
			dataModule0,
			dataModule1,
			dataModule2,
			dataModule3,
			dataModule4
		},
		computed:{
			user(){
				return this.$store.state.global.user
			}
		},
		watch:{
			user(){
				this.init();
			}
		}
	}
</script>
<style lang="scss" scoped>
	.data{
		padding-bottom: 100rpx;
		.top{
			padding: 0 28rpx;
			.top_title{
				font-size: $uni-font-size-big;
				font-weight: 600;
				padding: 20rpx 0;
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				.top_right{
					image{
						width: 50rpx;
						height: 50rpx;
						vertical-align: text-bottom;
						margin-left: 20rpx;
					}
				}
			}
			.top_list{
				image{
					width: 50%;
					height: 180rpx;
				}
			}
		}
	}
</style>
